package com.ruoyi.system.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.OrderAllocationConfig;
import com.ruoyi.system.service.IOrderAllocationConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单分配配置Controller
 *
 * @author hjf
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/order/config")
public class OrderAllocationConfigController extends BaseController {
    @Autowired
    private IOrderAllocationConfigService orderAllocationConfigService;

    /**
     * 查询订单分配配置列表
     */
    @PreAuthorize("@ss.hasPermi('order:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAllocationConfig orderAllocationConfig) {
        startPage();
        List<OrderAllocationConfig> list = orderAllocationConfigService.selectOrderAllocationConfigList(orderAllocationConfig);
        return getDataTable(list);
    }

    /**
     * 导出订单分配配置列表
     */
    @PreAuthorize("@ss.hasPermi('order:config:export')")
    //@Log(title = "订单分配配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderAllocationConfig orderAllocationConfig) {
        List<OrderAllocationConfig> list = orderAllocationConfigService.selectOrderAllocationConfigList(orderAllocationConfig);
        ExcelUtil<OrderAllocationConfig> util = new ExcelUtil<OrderAllocationConfig>(OrderAllocationConfig.class);
        util.exportExcel(response, list, "订单分配配置数据");
    }

    /**
     * 获取订单分配配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orderAllocationConfigService.selectOrderAllocationConfigById(id));
    }

    /**
     * 新增订单分配配置
     */
    @PreAuthorize("@ss.hasPermi('order:config:add')")
    //@Log(title = "订单分配配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderAllocationConfig orderAllocationConfig) {
        return toAjax(orderAllocationConfigService.insertOrderAllocationConfig(orderAllocationConfig));
    }

    /**
     * 修改订单分配配置
     */
    @PreAuthorize("@ss.hasPermi('order:config:edit')")
    //@Log(title = "订单分配配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderAllocationConfig orderAllocationConfig) {
        return toAjax(orderAllocationConfigService.updateOrderAllocationConfig(orderAllocationConfig));
    }

    /**
     * 删除订单分配配置
     */
    @PreAuthorize("@ss.hasPermi('order:config:remove')")
    //@Log(title = "订单分配配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderAllocationConfigService.deleteOrderAllocationConfigByIds(ids));
    }
}
